import { Language } from "../../../extend/language/Language";
import { GameDefConfig } from "./GameDefConfig";
import { PathConst } from "../../common/global/PathConst";
import { ImageInfo } from "../../../com/gengine/resource/info/ImageInfo";
import { GameMapConfig } from "./GameMapConfig";
import { ResourceManager } from "../../../com/gengine/resource/ResourceManager";
import { SceneInfo } from "../scene/map/SceneInfo";
import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { NPCInfo } from "../model/NPCInfo";
import { SceneEffectInfo } from "../model/SceneEffectInfo";
import { SArenaCrossStatues } from "../../../Message/Public/SArenaCrossStatues";
import { ParamsConst } from "../../common/global/ParamsConst";
import { EntityUtil } from "../scene/layer/utils/EntityUtil";
import { ThingUtil } from "../scene/layer/utils/ThingUtil";
import { SCrossFlowerToplistStatues } from "../../../Message/Public/SCrossFlowerToplistStatues";
import { ESex } from "../../../Message/Public/ESex";
import { SArenaCrossStatuePlayer } from "../../../Message/Public/SArenaCrossStatuePlayer";
import { StringHelper } from "../../../com/gengine/utils/StringHelper";
import { SWFModelConfig } from "./SWFModelConfig";
import { CareerType } from "../scene/player/entity/CareerType";
type int = number;
//class SceneConfig
    
    export  class SceneConfig
    {
        constructor()
        {
            
            var loc1=0;
            this._rankStr = Language.getString(11063);
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            this._npcMap = new Map<any, any> /* flash.utils.Dictionary */();
            if (SceneConfig._instance != null) 
            {
                throw new Error(" SceneConfig 单例 ");
            }
            this._mapArray = GameDefConfig.instance.getLoadMapConfig(1);
            var loc2=0;
            while (loc2 < this._mapArray.length) 
            {
                loc1 = int(this._mapArray[loc2]);
                this.addMiniMapInfo(loc1);
                this._mapArray[loc2] = loc1;
                ++loc2;
            }
            this._refreshMap = GameDefConfig.instance.getLoadMapConfig(2);
            var loc3=0;
            while (loc3 < this._refreshMap.length) 
            {
                this._refreshMap[loc3] = int(this._refreshMap[loc3]);
                ++loc3;
            }
            this._sceneEffect = GameDefConfig.instance.getLoadMapConfig(3);
            var loc4=0;
            while (loc4 < this._sceneEffect.length) 
            {
                this._sceneEffect[loc4] = int(this._sceneEffect[loc4]);
                ++loc4;
            }
            this.init();
            return;
        }

        /* internal  */addMiniMapInfo(arg1: int): void
        {
            var loc1=arg1 + "_mini.jpg";
            var loc2=arg1 + "/" + loc1;
            var loc3=PathConst.mapPath + loc2;
            var loc4;
            (loc4 = new ImageInfo({"name": loc1, "type":".JPG", "time": GameMapConfig.instance.getVersionById(arg1), "path": loc3})).loaclPath = PathConst.mapLocalPath + loc2;
            ResourceManager.addResource(loc4);
            return;
        }

        public SceneConfig.get allMap(): Map<any, any> /* flash.utils.Dictionary */
        {
            return this._map;
        }

        public init(): void
        {
            var loc3=0;
            var loc1=this._mapArray.length;
            var loc2=0;
            while (loc2 < loc1) 
            {
                loc3 = this._mapArray[loc2];
                this._map[loc3] = this.initSceneInfo(loc3);
                ++loc2;
            }
            this.initNPCIsAddToStage();
            return;
        }

        public getSceneInfo(arg1: int): SceneInfo
        {
            return this._map[arg1] as SceneInfo;
        }

        public getMapName(arg1: int): string
        {
            var loc1=this._map[arg1] as SceneInfo;
            if (loc1) 
            {
                return loc1.sMapDefine.name;
            }
            return "";
        }

        protected initSceneInfo(arg1: Object): SceneInfo
        {
            var loc2=null;
            var loc1=this._map[arg1] as SceneInfo;
            if (loc1 == null) 
            {
                loc2 = ConfigManager.instance.getJSONByFileName(arg1 + "_scene.json");
                if (loc2) 
                {
                    loc1 = new SceneInfo();
                    loc1.readObj(loc2);
                    if (this._refreshMap.indexOf(arg1) != -1) 
                    {
                        loc1.readBossRefreshPoint(ConfigManager.instance.getJSONByFileName(arg1 + "_BossRefreshPoint.json"));
                    }
                    if (this._sceneEffect.indexOf(arg1) != -1) 
                    {
                        loc1.readSceneEffect(ConfigManager.instance.getJSONByFileName(arg1 + "_sceneEffect.json"));
                    }
                    loc1.readBossAreaInfo(loc2);
                }
                else 
                {
                    throw new Error("未知的地图编码：" + arg1);
                }
            }
            return loc1;
        }

        /* internal  */initNPCIsAddToStage(): void
        {
            var loc2=null;
            var loc3=0;
            var loc4=0;
            var loc1=GameDefConfig.instance.getNPCNotAddToStageArray();
            var loc5=0;
            var loc6=loc1;
            for(loc2 of loc6) 
            {
                loc3 = loc2.id;
                loc4 = loc2.text;
                this.setNpcIsAddStage(loc3, false);
            }
            return;
        }

        public getSceneInfoByNpcId(arg1: int): SceneInfo
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            var loc4=0;
            var loc5=this._mapArray;
            for(loc2 of loc5) 
            {
                loc1 = this.getSceneInfo(loc2);
                var loc6=0;
                var loc7=loc1.npcInfos;
                for(loc3 of loc7) 
                {
                    if (!(!(loc3.tnpc == null) && loc3.tnpc.npcId == arg1)) 
                    {
                        continue;
                    }
                    return loc1;
                }
            }
            return null;
        }

        public getSceneInfoByEffectId(arg1: int): SceneInfo
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            var loc4=0;
            var loc5=this._mapArray;
            for(loc2 of loc5) 
            {
                loc1 = this.getSceneInfo(loc2);
                var loc6=0;
                var loc7=loc1.effectInfos;
                for(loc3 of loc7) 
                {
                    if (loc3.effectId != arg1) 
                    {
                        continue;
                    }
                    return loc1;
                }
            }
            return null;
        }

        public setNpcIsAddStage(arg1: int, arg2: Boolean): void
        {
            this.setNpcIsAddStageByInfo(this.getNpcInfo(arg1), arg2);
            return;
        }

        public setNpcIsAddStageByInfo(arg1: NPCInfo, arg2: Boolean): void
        {
            if (arg1) 
            {
                arg1.isAddStage = arg2;
            }
            return;
        }

        public setSceneEffectIsAddStageByInfo(arg1: SceneEffectInfo, arg2: Boolean): void
        {
            if (arg1) 
            {
                arg1.isAddStage = arg2;
            }
            return;
        }

        public getNpcInfo(arg1: int, arg2: int=-1): NPCInfo
        {
            var loc1=null;
            var loc2=null;
            if (arg2 != -1) 
            {
                loc1 = this.getSceneInfo(arg2);
                return loc1.getNpcInfo(arg1);
            }
            var loc3=0;
            var loc4=this._mapArray;
            for(arg2 of loc4) 
            {
                loc1 = this.getSceneInfo(arg2);
                var loc5=0;
                var loc6=loc1.npcInfos;
                for(loc2 of loc6) 
                {
                    if (!(!(loc2.tnpc == null) && loc2.tnpc.npcId == arg1)) 
                    {
                        continue;
                    }
                    return loc2;
                }
            }
            return null;
        }

        public setStatuesNpc(arg1: SArenaCrossStatues): void
        {
            if (!ParamsConst.instance.isArenaStatueShow) 
            {
                return;
            }
            var loc1=arg1.champion;
            var loc2=this.getNpcInfo(8000021);
            if (loc2) 
            {
                loc2.isAddStage = true;
                loc2.isClcik = false;
                if (loc2.tnpc) 
                {
                    loc2.tnpc.name = EntityUtil.getProxyNameByProxyAndServer(loc1.entityId.typeEx2, loc1.entityId.typeEx) + " · " + loc1.name;
                    loc2.tnpc.career = null;
                    loc2.statuePlayer = loc1;
                    loc2.tnpc.modelId = "statue_" + loc1.career + "_" + loc1.sex + ".swf";
                }
            }
            var loc3=0;
            var loc4=arg1.bestPlayers;
            for(loc1 of loc4) 
            {
                this.updateNpcInfo(loc1, loc1.rank + 8000010, false, "dx000001");
            }
            ThingUtil.isMoveChange = true;
            return;
        }

        public setCrossFlowerNpc(arg1: SCrossFlowerToplistStatues): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=arg1.bestPlayers;
            for(loc1 of loc3) 
            {
                if (loc1.sex == ESex._ESexMan) 
                {
                    this.updateNpcInfo(loc1, loc1.rank + 8000030, true, "dx000002");
                    continue;
                }
                this.updateNpcInfo(loc1, loc1.rank + 8000040, true, "dx000002");
            }
            ThingUtil.isMoveChange = true;
            return;
        }

        /* internal  */updateNpcInfo(arg1: SArenaCrossStatuePlayer, arg2: int, arg3: Boolean=true, arg4: string="dx000001"): void
        {
            var loc1;
            if (loc1 = this.getNpcInfo(arg2)) 
            {
                loc1.isAddStage = true;
                loc1.isClcik = arg3;
                loc1.statuePlayer = arg1;
                if (loc1.tnpc) 
                {
                    loc1.tnpc.name = arg1.name;
                    loc1.tnpc.career = StringHelper.substitute(this._rankStr, arg1.rank);
                    loc1.tnpc.modelId = SWFModelConfig.instance.getSwfUrl(arg4, arg1.sex, CareerType.getCareer(arg1.career));
                }
            }
            return;
        }

        public getEffectInfo(arg1: int, arg2: int=-1): SceneEffectInfo
        {
            var loc1=null;
            var loc2=null;
            if (arg2 != -1) 
            {
                loc1 = this.getSceneInfo(arg2);
                return loc1.getEffectInfo(arg1);
            }
            var loc3=0;
            var loc4=this._mapArray;
            for(arg2 of loc4) 
            {
                loc1 = this.getSceneInfo(arg2);
                var loc5=0;
                var loc6=loc1.effectInfos;
                for(loc2 of loc6) 
                {
                    if (loc2.effectId != arg1) 
                    {
                        continue;
                    }
                    return loc2;
                }
            }
            return null;
        }

        public static get instance(): SceneConfig
        {
            if (SceneConfig._instance == null) 
            {
                SceneConfig._instance = new SceneConfig();
            }
            return SceneConfig._instance;
        }

        /* internal */ /* var */_rankStr: string;

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_mapArray: Array<any>;

        /* internal */ /* var */_refreshMap: Array<any>;

        /* internal */ /* var */_sceneEffect: Array<any>;

        /* internal */ /* var */_npcMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: SceneConfig;
    }
